<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <title>websocket</title>
</head>

<body>
<h1>Echo Test</h1>
<input type="text" id="sendTxt">
<button id="sendBtn">发送</button>
<div id="recv"></div>
<script>
    var websocket = new WebSocket('ws://localhost:8080/ws1?uid=123');
    websocket.onopen = function() {
        console.log('websocket open');
        document.getElementById('recv').innerHTML = 'Connect';
    }
    websocket.onclose = function() {
        console.log('websocket cloas');
    }
    websocket.onmessage = function(e) {
        console.log(e.data);
        document.getElementById('recv').innerHTML = e.data;
    }
    document.getElementById('sendBtn').onclick = function() {
        var txt = document.getElementById('sendTxt').value;
        websocket.send(txt)
    }

    var websocket1 = new WebSocket('ws://localhost:8080/ws1?uid=123');
    websocket1.onopen = function() {
        console.log('websocket open');
        document.getElementById('recv').innerHTML = 'Connect';
    }
    websocket1.onclose = function() {
        console.log('websocket cloas');
    }
    websocket1.onmessage = function(e) {
        console.log(e.data);
        document.getElementById('recv').innerHTML = e.data;
    }
    document.getElementById('sendBtn').onclick = function() {
        var txt = document.getElementById('sendTxt').value;
        websocket1.send(txt)
    }
</script>
</body>

</html>
